package se.webbzon.oschi01.metric;

public class XWangJaroWinklerMetric implements Metric<String> {
	
	private final Metric<String> xWang = new XWangMetric();
	
	private final Metric<String> jaroWinkler = new JaroWinklerMetric();
	
	private final double xww, jww;
	
	public XWangJaroWinklerMetric() {
		this(0.5);
	}
	
	public XWangJaroWinklerMetric(double xWangWeight) {
		if (xWangWeight < 0 || xWangWeight > 1)
			throw new IllegalArgumentException("The xWangWeight must be between 0 and 1.");
		xww = xWangWeight;
		jww = 1 - xWangWeight;
	}

	@Override public double distance(String lhs, String rhs) {
		return xww * xWang.distance(lhs, rhs) + jww * jaroWinkler.distance(lhs, rhs);
	}

}
